package top.banner.es;

import com.fasterxml.jackson.databind.ObjectMapper;
import org.elasticsearch.action.index.IndexRequest;
import org.elasticsearch.action.index.IndexResponse;
import org.elasticsearch.client.RequestOptions;
import org.elasticsearch.client.RestHighLevelClient;
import org.elasticsearch.common.xcontent.XContentType;

import java.io.IOException;

/**
 * @author XGL
 */
public class DocInstall {
    final static ObjectMapper objectMapper = new ObjectMapper();

    public static void main(String[] args) throws IOException {
        final RestHighLevelClient client = ESClient.init();

        final IndexRequest request = new IndexRequest();
        request.index("user").id("1001");
        final String userJson = objectMapper.writeValueAsString(new User("zhangsan", "男", 30));
        request.source(userJson, XContentType.JSON);

        final IndexResponse response = client.index(request, RequestOptions.DEFAULT);

        System.out.println(response.getResult());

        client.close();
    }
}
